/* BEGIN JS DOCUMENT READY RENDERING */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', analyticsAccount]);
_gaq.push (['_gat._anonymizeIp']);
_gaq.push(['_setDomainName', analyticsDomain]);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);

if(ga_is_new_user=="1"){
	_gaq.push(['_trackEvent', 'Authentication', 'LoggedIn', 'Facebook']);
}if(ga_is_login_denied=="1"){
	_gaq.push(['_trackEvent', 'Authentication', 'UserDenied', 'Facebook']);
}if(ga_is_logged_out=="1"){
  	_gaq.push(['_trackEvent', 'Authentication', 'LoggedOut', 'Facebook']);
}if(ga_comment_posted=="1"){
  	_gaq.push(['_trackEvent', 'Comment', 'CommentPosted', ga_article_title]);
}

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

function relocateExtContent(){
	// define the size for the 3 columns
	var browserWidth = $(window).width();
	var centerWidth = 650;
	$("#knMaster").width(browserWidth);
	$("#knMasterCenter").width(centerWidth);
	var backgroundWidth = ((browserWidth-centerWidth)/2);
	$("#knMasterLeft").width(backgroundWidth);
	$("#knMasterRight").width(backgroundWidth);
	
	// relocate the codeblocks and the ads
	$("#dfp_left").offset($("#knMasterLeftSpace").offset());
	$("#dfp_right").offset($("#knMasterSpaceRight").offset());
	$(".codeblock").width($("#knMasterCenterContent").width()-10);
}

// initially relocate the content
relocateExtContent();

/* attach to the resize function */
$(window).resize(function() {
	relocateExtContent();
});

SyntaxHighlighter.all();

/* END JS DOCUMENT READY RENDERING */

/* prompts the user and when confirmed 
 * deletes a comment the admin or author
 * wants to delete */
function deleteComment(id){
	var textAbort = $("#textAbort").val();
	var textDeleteComment = $("#textDeleteComment").val();
	var buttonOpts = {};
	buttonOpts[textAbort] = function() {
		$( this ).dialog( "close" );
	}
	buttonOpts[textDeleteComment] = function() {
		$("#deleteComment").val(id);
		$("#deleteCommentForm").submit();
	}

	$( "#dialog-delete-comment" ).dialog({
		dialogClass: "knDialogBox",
		resizable: false,
		height:160,
		width:400,
		modal: true,
		buttons: buttonOpts
	})	
}

/* executes a site-search */
function search(q){
	location.href = "/s/"+escape(q)+"?ga_search_keyword="+escape(q);
}

/* opens the mail contact form */
function knMailContact(){
	window.open("/ext/contactform.php",
				"Kontakt","height=760,width=500,resizable=no,scrollbars=no,"
				+"status=no,toolbar=no,menubar=no,dependent=yes");
}

/* opens the recommendation form */
function knMailRecommend(pageItem){
	window.open("/ext/recommend.php?article="+pageItem,
				"Kontakt","height=760,width=500,resizable=no,scrollbars=no,"
				+"status=no,toolbar=no,menubar=no,dependent=yes");
}

function knLegalInformation(){
	window.open("/ext/legal.php",
				"Anbieterkennung","height=760,width=500,resizable=no,scrollbars=yes,"
				+"status=no,toolbar=no,menubar=no,dependent=yes");
}

function openAdminWindow(){
	window.open("/admin", "AdminWindow", "width=800,height=600,left=50,top=50,"
				+ "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

function share(network){
	var links = new Object();
	links["twitter"] = "http://twitter.com/intent/tweet?text=[title]&url=[url]";
	links["facebook"] = "http://www.facebook.com/sharer/sharer.php?u=[url]&t=[title]";
	links["google"] = "http://www.google.com/buzz/post?url=[url]&title=[title]&imageurl=&message=";
	links["yahoo"] = "http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=[url]&t=[title]";
	links["linkedin"] = "http://www.linkedin.com/shareArticle?mini=true&url=[url]&title=[title]&summary=&source=";
	links["bebo"] = "http://www.bebo.com/c/share?Url=[url]&Title=[title]";
	links["blogger"] = "http://www.blogger.com/blog_this.pyra?t&u=[url]&n=[title]&pli=1";
	links["delicious"] = "http://delicious.com/save?url=[url]&title=[title]";
	links["digg"] = "http://digg.com/submit?phase=2&url=[url]&title=[title]";
	links["stumbleupon"] = "http://www.stumbleupon.com/submit?url=[url]&title=[title]";
	links["xing"] = "https://www.xing.com/app/user?op=share&url=[url]&title=[title]";
	
	var target = links[network];
	target = target.replace('[title]',share_page_title);
	target = target.replace('[url]',escape(location.href));
	
	window.open(target);
}